<?php
include_once './templates/header.php';

$cid = isset($_GET['cid']) ? $_GET['cid'] : 0;

if (!empty($cid)) {

    $result4 = mysql_query("SELECT * FROM `products` WHERE active = 1 AND category_id = '" . $cid . "'");
if($result4 != FALSE) {
    while ($row4 = mysql_fetch_array($result4)) {

        $product_grid_item .= '<div class="col-sm-4">
                        <div class="product-image-wrapper">
                            <div class="single-products">
                                <div class="productinfo text-center">
                                    <img src="admin/assets/product_images/' . $row4['product_image_url'] . '" alt="" />
                                    <h2>' . $row4['category'] . '<br/>' . $row4['product'] . '</h2>
                                    <h4>' . $row4['product_code'] . '</h4>
                                    <p>' . $row4['summary'] . '</p>
                                </div>
                                <a href="product_details.php?pid=' . $row4['product_id'] . '">
                                <div class="product-overlay">
                                    <div class="overlay-content">
                                        <h2>' . $row4['category'] . '<br/>' . $row4['product'] . '</h2>
                                        <h4>' . $row4['product_code'] . '</h4>
                                        <p>' . $row4['summary'] . '</p>
                                    </div>
                                </div>
                                </a>
                            </div>
                            <div class="choose">
                                <ul class="nav nav-pills nav-justified">


                                </ul>
                            </div>
                        </div>
                    </div>';
    }
  }
} else {
    // If no categories are chosen show 9 latest products

    $result4 = mysql_query("SELECT *,p.product_id as ppid FROM `products` p, `categories` c
                            WHERE p.active = 1 AND c.active=1 AND p.category_id = c.category_id
                            ORDER BY p.product_id DESC");

    while ($row4 = mysql_fetch_array($result4)) {

        $product_grid_item .= '<div class="col-sm-4">
                        <div class="product-image-wrapper">
                            <div class="single-products">
                                <div class="productinfo text-center">
                                    <img src="admin/assets/product_images/' . $row4['product_image_url'] . '" alt="" />
                                    <h2>' . $row4['category'] . '<br/>' . $row4['product'] . '</h2>
                                    <h4>' . $row4['product_code'] . '</h4>
                                    <p>' . $row4['summary'] . '</p>
                                </div>
                                <a href="product_details.php?pid=' . $row4['ppid'] . '">
                                <div class="product-overlay">
                                    <div class="overlay-content">
                                        <h2>' . $row4['category'] . '<br/>' . $row4['product'] . '</h2>
                                        <h4>' . $row4['product_code'] . '</h4>
                                        <p>' . $row4['summary'] . '</p>
                                    </div>
                                </div>
                                </a>
                            </div>
                            <div class="choose">
                                <ul class="nav nav-pills nav-justified">


                                </ul>
                            </div>
                        </div>
                    </div>';
    }
}
?>

<section id="slider"><!--slider-->
    <div class="container">
	
        <div class="row">
            <div class="col-sm-12">
				<h2 class="title text-center">Products</h2>
            </div>
        </div>
    </div>
</section><!--/slider-->

<section>
    <div class="container">
        <div class="row">
            <div class="col-sm-3">
                <?php include_once './templates/left_sidebar.php'; ?>
            </div>

            <div class="col-sm-9 padding-right">
                <div class="features_items"><!--features_items-->
                    <h2 class="title text-center"><?php print $category; ?></h2>

                    <?php print $product_grid_item; ?>

                </div><!--features_items-->
            </div>
        </div>
    </div>
</section>

<?php
include_once './templates/footer_widget.php';
include_once './templates/footer.php';
?> 